<?php
defined('_JEXEC') or die;
abstract class RaovatHelper{
	public  static function getMenu()
	{
		$app    = JFactory::getApplication();
		$db = JFactory::getDBO();
		$query = $db->getQuery(true);
		$query->select('title ,id');
		$query->from('#__categories');
		$query->where('extension="com_raovat"');
		$query->where('parent_id=1');
		$db->setQuery($query);
		$rows = $db->loadAssocList();
		$string ="<ul class='menu-raovat-top'>";
  		foreach($rows as $key=>$value){
  			$string .= "<li><a href='".JRoute::_('index.php?option=com_raovat&view=raovats&cat='.$value['id'].'&Itemid='.JRequest::getVar('Itemid'))."'>{$value['title']}</a>";
  				$query->clear();
  				$query->select('title ,id');
				$query->from('#__categories');
				$query->where('extension="com_raovat"');
				$query->where('parent_id='.$value['id']);
				$db->setQuery($query);
		  		$rows_childs = $db->loadAssocList();
		  		if ($rows_childs){
		  			$string .= "<ul>";
		  			foreach($rows_childs as $k=>$v){
						$string.="<li><a href ='".JRoute::_('index.php?option=com_raovat&view=raovats&cat='.$v['id'].'&Itemid='.JRequest::getVar('Itemid'))."'>{$v['title']}</a></li>";
				    }
				    $string .= "</ul>";
		  		}
  				$string .="</li>";
  		}
  		$string.="</ul>";
  		$region = array(''=>'(Chọn Tỉnh/Thành Rao vặt)',1=>'Toàn quốc',2=>'TP Hà Nội',3=>'TP Hồ Chí Minh',4=>'Các tỉnh phía Bắc',5=>'Các tỉnh phía Nam');
  		$string.="<form action='index.php?option=com_raovat&view=search' menthod='get'><ul class='search-form'>";
  		$string .='<li><label>Tìm kiếm</label></li>';
  		$string .='<li><input type="text" name="search" value="'.$app->input->get('search','','string').'"/></li>';
  		$string .='<li>'.JHtml::_('select.genericlist', $region, 'region', 'class="inputbox" size="1"','value', 'text', $app->input->get('region', 0, 'uint')).'</li>';
  		$string .='<li><input class="search" type="submit" value="search" />
  		<input type="hidden" value="search" name="view" />
  		<input type="hidden" value="com_raovat" name="option" /></li>';
  		$string.="</ul></form>";
	  	return $string;
	}
	
}
